package app.projeto.dao;

import java.sql.ResultSet;
import java.sql.Statement;

import app.projeto.entity.Milestone;
import app.projeto.util.Factory;
import app.projeto.util.Query;

public class DaoMilestone extends Dao {
	
	/**
	 * Busca todas os milestones apenas pelo id do projeto
	 * 
	 * @param obj
	 * @return
	 * @throws Exception
	 */
	public Object[] findByIdProject(Object obj) throws Exception{
		Milestone milestone = (Milestone) obj;
		try {
			String sql = "select " + Query.getFieldNames(milestone,true) +
						" from " + Query.getTableName(milestone) + " " +
						" where idprojeto = " + milestone.getProjeto().getIdProjeto();
			System.out.println(sql);
			Statement stmt = this.getConnection().createStatement();
			ResultSet rst = stmt.executeQuery(sql);
			return Factory.createByResultSet(rst, milestone.getClass());
		} catch (Exception e) {
			this.rollback();
			throw e;
		}
	}


}
